import React, { Component } from 'react';
import { TouchableOpacity,Linking } from 'react-native';
import PropTypes from 'prop-types';

export default class TouchableOpenUrl extends Component {
	constructor(props) {
		super(props);
	}

	protoTypes = {
		url: PropTypes.string,
	};

	render() {
		return (
			<TouchableOpacity
				onPress={() => {
					Linking.canOpenURL(this.props.url)
						.then(supported => {
							if (!supported) {
								alert("Can't handle url: " + this.props.url);
							} else {
								return Linking.openURL(this.props.url);
							}
						})
						.catch(err => alert('An error occurred', err));
				}}
			>
				{this.props.children}
			</TouchableOpacity>
		);
	}
}
